package com.zcl.lambda.test1;


import org.junit.Test;

import java.util.Comparator;

public class LambdaTest {
    @Test
    public void test1(){
        Runnable r1 = new Runnable(){

            @Override
            public void run() {
                System.out.println("running....");
            }
        };
        // 1.匿名实现类实现接口方法并调用
        r1.run();
        // lambda表达方式一
        Runnable r2 = ()-> System.out.println("running....");



        // 2.非匿名实现类实现接口方法并调用
//        RunableImpl runable = new RunableImpl();
//        runable.run();
//
    }

    @Test
    public void test2(){
        Comparator<Integer> com1 = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1, o2);
            }
        };
        System.out.println(com1.compare(12, 21));
        // 1.
        Comparator<Integer> com2 = (o1, o2) -> Integer.compare(o1, o2);
        System.out.println(com2.compare(12,10));

        //2.
        Comparator<Integer> com3 =Integer::compareTo;
        System.out.println(com3.compare(10,20));

    }
}


//public class RunableImpl implements Runnable{
//
//    @Override
//    public void run() {
//        System.out.println("非匿名实现类");
//
//    }
//}
